package logic

import (
	"context"
	"strconv"
	"week1_zg6/orderrpc/model/mysql"

	"week1_zg6/orderrpc/internal/svc"
	"week1_zg6/orderrpc/order"

	"github.com/zeromicro/go-zero/core/logx"
)

type RenderTheOrderLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewRenderTheOrderLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RenderTheOrderLogic {
	return &RenderTheOrderLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *RenderTheOrderLogic) RenderTheOrder(in *order.RenderTheOrderRequest) (*order.RenderTheOrderResponse, error) {
	atoi, err := strconv.Atoi(in.OrderID)
	if err != nil {
		return nil, err
	}
	whereOrder := mysql.WhereOrder(int64(atoi))

	return &order.RenderTheOrderResponse{
		OrderID:         whereOrder.OrderId,
		UserID:          whereOrder.UserId,
		OrderStatus:     whereOrder.OrderStatus,
		ShippingAddress: whereOrder.ShippingAddress,
		TotalAmount:     whereOrder.TotalAmount,
	}, nil
}
